<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  User: dw
  Date: 2019/12/16
  Time: 23:13
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>XXX公司测评系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="../css/date.css">
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">发布时间</label>
            <div class="layui-input-block">
              <input type="text" name="createTime" class="createTime date" placeholder="请输入发布时间" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">

            <div class="layui-inline">
              <label class="layui-form-label">编号</label>
              <div class="layui-input-block">
                <input type="text" name="queId"  placeholder="请输入问题编号" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">测评对象</label>
              <div class="layui-input-block">
                <input type="text" name="voteBy"  placeholder="请输入测评对象" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>

      <div class="layui-card-body">
        <table id="answerList" lay-filter="answerList">

        </table>
      </div>
      </div>
      </div>
  </div>

  <script src="../../../layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'useradmin', 'table','form','laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,laydate = layui.laydate
    ,table = layui.table;
    //时间显示
      laydate.render({
          elem: '.createTime'
          ,format: 'yyyy-MM-dd'
      });
      //监听搜索
      form.on('submit(LAY-user-front-search)', function(data){
          var field = data.field;
          //执行重载
          table.reload('answerList', {
              where: field
          });
      });
    //加载表格
    table.render({
        elem:"#answerList",
        height:500,
        url:"/vote/loadAnswerList",
        page:true,
        where:{
            name:''
        },
        limit:10,
        cols:[[
            {field:"ansId",width:'6%',title:"编号",sort:true},
            {field:"queId",width:'24%',title:"问题",templet:function(d){
                return d.question.queTitle;
                }},
            {field:"answer",width:'24%',title:"答案"},
            {field:"createBy",width:'6%',title:"发布人",templet:function(d){
                   return d.createUser.userName;
                }},
            {field:"answerBy",width:'6%',title:"回答人",templet:function(d){
                    return d.answerUser.userName;
                }},
            {field:"createTime",width:'10%',title:"发布时间"},
            {field:"answerTime",width:'10%',title:"回答时间"},
            {field:"voteBy",width:'10%',title:"测评对象",templet:function(d) {
                   if(d.voteBy == "0"){
                       return "<span class='layui-badge layui-bg-green'>其他</span>";
                   }else if(d.voteUser != null && d.voteDepartment == null){
                       return "<span class='layui-badge layui-bg-blue'>"+d.voteUser.userName+"</span>";
                   }else{
                       return "<span class='layui-badge layui-bg-orange'>"+d.voteDepartment.depName+"</span>";
                   }

      }},
            {field:"opreation",width:'18%',title:"操作",templet:function () {
                    return "<button type='button' class='layui-btn' style='position: relative; top:0px' lay-event='ok'>" +
                        "  <i class='layui-icon' style='position: relative; top:-12px'>&#x1005;</i> 同意" +
                        "</button>" +
                        "<button type='button'  class='layui-btn  layui-btn-danger' style='position: relative; top:0px' lay-event='no'>" +
                        "  <i class='layui-icon' style='position: relative; top:-10px'>&#x1007;</i> 退回" +
                        "</button>"
                }},

        ]],
        id:'answerList',
        parseData:function (res) {
            console.log(res);
        }
    });
      //点击事件触发(给table添加监听事件)
      table.on('tool(answerList)',function (obj) {
          //获取当前行的所有记录 键值对，见识field的属性，值是后台的数据
          var data = obj.data;
          var id = data.id;
          //获取触发事件
          var event = obj.event;
          if(event == "ok"){
              //同意
              $.ajax({
                  url: '/answer/updateCheck?check=1&ansId='+data.ansId+'',
                  type: 'post',
                  data: {},
                  dateType: "json",
                  success: function (res) {
                      var msg = res.msg;
                      if(msg == "ok"){
                          layer.msg("审核成功");
                          layer.close(index);
                          //刷新
                          $(".layui-laypage-btn")[0].click();
                      }else{
                          layer.msg("审核成功");
                      }
                  }
              });
          }else{
              //驳回
              $.ajax({
                  url: '/answer/updateCheck?check=1&ansId='+data.ansId+'',
                  type: 'post',
                  data: {},
                  dateType: "json",
                  success: function (res) {
                      var msg = res.msg;
                      if(msg == "ok"){
                          layer.msg("退回成功");
                          layer.close(index);
                          //刷新
                          $(".layui-laypage-btn")[0].click();
                      }else{
                          layer.msg("退回成功");
                      }
                  }
              });

          }
      });

  });



  </script>
</body>
</html>
